$(function(){
    //侧边栏
    $("#nav-main1").addClass('nav-active');
    $("#nav-main1").find(".nav-icon-img").attr("src",'/Extend/images/aside-icon/manageBuilding1.svg');
    $("#nav-main1").find('.nav-triangle').fadeIn(200);
    $(".nav-child").slideDown(300);


    //表格没有内容时。。。
    var tr_len=$('.building-list li').length
    var keys=$("#key").val();
    var mark=$("#mark").val();
    var company=$("#company").val();
    var window_url= "/manage/index/index?mark="+mark+"&company="+company+"";
    if(tr_len<=0 && keys=='' ){
        $('.building-resault').empty().append(
            "<img class='empty-img' src='/Extend/images/operation-icon/empty.svg' alt='暂无数据' title='暂无数据'>"+
            "<p class='empty-font'>暂时没有相关数据</p>"
        )
    }else if(tr_len<=0 && keys!=='' ){
        $('.building-resault').empty().append(
            '<img class="empty-img" src="/Extend/images/operation-icon/empty.svg" alt="暂无数据" title="暂无数据">'+
            '<p class="empty-font">暂时没有相关数据<a href = "'+window_url+'">查看全部</a></p>'
        )
    }


    //选择公司
    $('.nav-child li').click(function(){
        var company=$(this).attr("data-company");
        if(company=="th"){
            window.location.href="/manage/index/index?mark=qb&company=th"
        }else if(company=="lz"){
            window.location.href="/manage/index/index?mark=qb&company=lz"
        }else if(company=="fj"){
            window.location.href="/manage/index/index?mark=qb&company=fj"
        }else if(company=="hc"){
            window.location.href="/manage/index/index?mark=qb&company=hc"
        };
    })
    //种类
    $('.resualt-type li').click(function(){
        var mark=$(this).attr("data-mark");
        $("#mark").val(mark);
        myForm.submit();
    })
    //编辑楼盘
    $(".editBuilding").click(function(){
        var id=$(this).closest(".building-li").attr("data-id");
        window.location.href="/manage/index/inserts?id="+id;
    })
    //取消楼盘

    $(".cancelBuilding").click(function(){
        var company=$("#company").val();
        var input_val={};
        input_val["id"]=$(this).closest(".building-li").attr("data-id");
        if(company=="hc"){
            input_val["sign"]=1;
        }
        $.ajax({
            type: 'post',
            url: '/manage/Building/delYx',
            data:input_val,
            success: function (msg) {
                console.log(msg)
                if (msg.code == '1') {
                    $('.alert-info-font').text(msg.message);
                    $('.alert-info').fadeIn(300);
                    $('.alert-info-btn').on('click',function(){
                        window.location.href=window.location.href;
                    })
                } else {
                    $('.alert-info-font').text(msg.message);
                    $('.alert-info').fadeIn(300);
                    $('.alert-info-btn').on('click',function(){
                        $('.alert-info').fadeOut(300);
                    })
                }
            }
        })
    })

    //添加类别
    $(".add-which-type").change(function(){
        var company=$("#company").val();
        var input_val={};
        input_val["id"]=$(this).attr("data-id");
        input_val["type"]=$(this).val();
        if(company=="hc"){
            input_val["sign"]=1;
        }
        console.log(input_val)
        $.ajax({
            type: 'post',
            url: '/manage/Building/addYx',
            data:input_val,
            success: function (msg) {
                console.log(msg)
                if (msg.code == '1') {
                    $('.alert-info-font').text(msg.message);
                    $('.alert-info').fadeIn(300);
                    $('.alert-info-btn').on('click',function(){
                        window.location.href=window.location.href;
                    })
                } else {
                    $('.alert-info-font').text(msg.message);
                    $('.alert-info').fadeIn(300);
                    $('.alert-info-btn').on('click',function(){
                        $('.alert-info').fadeOut(300);
                    })
                }
            }
        })
    })



    //调整顺序
    function newOrder(input_val){
        var company=$("#company").val();
        if(company=="hc"){
            input_val["sign"]=1
        }
        console.log(input_val)
        $.ajax({
            type: 'post',
            url: '/manage/BuildingList/upload',
            data:input_val,
            success: function (msg) {
                console.log(msg)
                if (msg.code == '1') {
                    $('.alert-info-font').text(msg.message);
                    $('.alert-info').fadeIn(300);
                    $('.alert-info-btn').on('click',function(){
                        window.location.href=window.location.href;
                    })
                } else {
                    $('.alert-info-font').text(msg.message);
                    $('.alert-info').fadeIn(300);
                    $('.alert-info-btn').on('click',function(){
                        $('.alert-info').fadeOut(300);
                    })
                }
            }
        })
    }
    // 置顶
    $(".topest").click(function(){
        var input_val={}
        input_val["order"]=$(this).attr("data-order");
        input_val["id"]=$(this).closest(".building-li").attr("data-id");
        console.log(input_val)
        newOrder(input_val)
    })
    //上移
    $(".goUp").click(function(){
        var input_val={}
        input_val["order"]=$(this).attr("data-order");
        input_val["id"]=$(this).closest(".building-li").attr("data-id");
        console.log(input_val)
        newOrder(input_val)
    })
    //下移
    $(".goDown").click(function(){
        var input_val={}
        input_val["order"]=$(this).attr("data-order");
        input_val["id"]=$(this).closest(".building-li").attr("data-id");
        console.log(input_val)
        newOrder(input_val)
    })
    //删除
    $(".deleteBuilding").click(function(){
        var id=$(this).closest(".building-li").attr("data-id");
        $('.alert-info-font').text("你确定删除吗？");
        $('.alert-info').fadeIn(300);
        $('.alert-info-btn').attr('data-id',id);
        $('.alert-info-btn').addClass("alert-delete-this");
        return false;
    })
    $(".alert-info-inner").on("click", ".alert-delete-this", function () {
        var id=$(this).attr("data-id")
        console.log(id)
        $.ajax({
            type: 'post',
            url: '/manage/building/dels',
            data:{id:id},
            success: function (msg) {
                console.log(msg)
                if (msg.code == '1') {
                    window.location.href=window.location.href;
                } else {
                    $('.alert-info-font').text(msg.message);
                    $('.alert-info').fadeIn(300);
                    $('.alert-info-btn').on('click',function(){
                        $('.alert-info').fadeOut(300);
                    })
                }
            }
        })
    })
})